//
//  VideoDetailViewController.m
//  网易新闻
//
//  Created by lanou3g on 15/10/29.
//  Copyright © 2015年 马文强. All rights reserved.
//

#import "VideoDetailViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface VideoDetailViewController ()

@property (nonatomic, strong) MPMoviePlayerController *player;

@end

@implementation VideoDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadPlayer];
}
- (void)loadPlayer{
    _player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:_mp4_url]];
    _player.view.frame = self.view.frame;
    //设置视频播放的适配
    _player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    _player.controlStyle = MPMovieControlStyleEmbedded;
    [self.view addSubview:_player.view];
    //播放视频
    [_player play];
    //监听Done的时间
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exit) name:MPMoviePlayerDidExitFullscreenNotification object:nil];

    //播放结束的时候退出来
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exit) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    
}

- (void)exit
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
